from functools import wraps
from flask import jsonify
from flask_jwt_extended import get_jwt

def admin_required(fn):
    @wraps(fn)
    def wrapper(*args, **kwargs):
        # Get JWT claims
        claims = get_jwt()
        
        # Check if user has admin role
        if claims.get('role') != 'admin':
            return jsonify({'code': 403, 'message': '权限不足，需要管理员权限', 'data': None}), 403
        
        return fn(*args, **kwargs)
    return wrapper 